<?php
/**
 * JE Career package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class hostingrajacareerControllerApplied_openings extends JController
{
	function __construct( $config = array() )
	{
		parent::__construct( $config );
		$this->registerTask( 'add',	'edit' );
		$this->registerTask( 'new',	'edit' );
		$this->registerTask( 'apply', 'save' );
		$this->registerTask( 'unpublish',	'publish' );
	}

	function display()
	{
		JRequest::setVar( 'view', 'applied_openings');
		parent::display();
	}

	function edit()
	{
		JRequest::setVar( 'view', 'applied_openings');
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);
		parent::display();
	}
	function cancel()
	{
		$msg 			= JText::_( 'JWD_MSG_CANCELED' );
		$this->setRedirect( 'index.php?option=com_hostingrajacareer&controller=applied_openings', $msg );
	}
	// save the subscriber
	function save()
	{
		$model 			= $this->getModel('applied_openings');

		if ($cid = $model->store())
		{
			$msg 		= JText::_( 'JWD_ITEM_SAVE_SUCCESS' );
		}
		else {
			$msg 		= JText::_( 'JWD_ITEM_SAVE_FAILED' );
		}
		if($this->_task == 'apply')
		{
			$link 		= 'index.php?option=com_hostingrajacareer&controller=applied_openings&task=edit&cid[]='. $cid;
		}
		else
		{
			$link 		= 'index.php?option=com_hostingrajacareer&controller=applied_openings';
		}
		$this->setRedirect($link, $msg);
	}
	// delete a subscriber
	function remove()
	{
		$model 			= $this->getModel('applied_openings');

		$this->setRedirect( 'index.php?option=com_hostingrajacareer&controller=applied_openings');

		if($model->remove()) {
			$msg 		= JText::_( 'JWD_ITEM_DELETE_SUCCESS' );
		}
		else {
			return JError::raiseWarning( 500, JText::_( 'JWD_ITEM_DELETE_FAILURE' ));
		}

		$this->setRedirect( 'index.php?option=com_hostingrajacareer&controller=applied_openings', $msg );
	}
	function publish()
	{
		$model 			= $this->getModel('applied_openings');

		$result 		= $model->publish();

		$this->setRedirect( 'index.php?option=com_hostingrajacareer&controller=applied_openings');

		if($result ==  1) {
			$msg 		= JText::_( 'JWD_ITEM_PUBLSIH_SUCCESS' );
		}
		else if ($result == -1) {
			return JError::raiseWarning( 500, JText::_( 'JWD_ITEM_PUBLSIH_FAILURE' ));
		}
		else if($result ==  2) {
			$msg 		= JText::_( 'JWD_ITEM_UNPUBLSIH_SUCCESS' );
		}
		else if ($result == -2) {
			return JError::raiseWarning( 500, JText::_( 'JWD_ITEM_UNPUBLSIH_FAILURE' ));
		}
		else if ($result == 0) {
			return JError::raiseNotice( 500, JText::_( 'JWD_NO_ITEM_SELECTED' ));
		}
		$this->setRedirect( 'index.php?option=com_hostingrajacareer&controller=applied_openings', $msg);
	}
}
?>